#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 19-5-28 下午5:11
# @Author  : Jason
# @Site    : 
# @File    : common.py.py
# @Software: PyCharm
import functools
# 共用的自定义工具类
from flask import current_app
from flask import g
from flask import session

from info.models import User


def do_index_class(index):
    if index ==0:
        return 'first'
    elif index ==1:
        return 'second'
    elif index ==2:
        return 'third'
    return ''

def user_login_data(f):
    #使用functiontoool.wraps去装饰内层函数,可以保持当前装饰器去装饰的函数的__name__的值不变
    @functools.wraps(f)
    def wrapper(*args,**kwargs):
        user_id = session.get('user_id', None)
        user = None
        if user_id:
            # 查询用户的模型
            try:
                user = User.query.get(user_id)
            except Exception as  e:
                current_app.logger.erro(e)

            # 把你要查询的数据赋值给g变量
        g.user=user
        return f(*args,**kwargs)
    return wrapper